/**
 * 发票 - 编辑页面
 * @author liuw
 * @date 2019/09/04
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        layui = win.layui,
        vueData = {
            isAdd: false,
            form: {
                GWEF002_NAME:null,
                GWEF020_NAME:null,
                GWEF021_NAME:null,
                GWEFMLEGAL_NAME:null,
                GWEFPLANT_NAME:null
            },
            rules: {
                GWEFDOCNO: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWEFDOCDATE: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWEF002: [
                    {required: true, message: '不可为空', trigger: 'change'}
                ],
                GWEFMLEGAL: [
                    {required: true, message: '不可为空', trigger: 'change'}
                ]
            },
            digit: {
                rate: 100,
                price: 100,
                amount: 100
            },
            total: {
                rows: 0,
                num:0,
                original_taxSum: 0,
                original_tax:0,
                original_sum:0,
                taxSum: 0,
                tax:0,
                sum:0
            }
        },
        cols = [[
            {type:'checkbox',fixed: 'left'},
            {field: "GWEFDOCNO", title: "开票号码",width: 150},
            {field: "GWEFSEQ", title: "项次",width: 100},
            {field: "GWEF001", title: "开票申请单号",width: 150},
            {field: "GWEFDOCDATE", title: "单据日期",width: 100},
            {field: "GWEF002_NAME", title: "客户",width: 100},
            {field: "GWEF003", title: "出货单号",width: 180},
            {field: "GWED102", title: "出货单项次",width: 100},
            {field: "GWEF004", title: "订单号",width: 150},
            {field: "GWEC101", title: "订单项次",width: 100},
            {field: "GWEF005", title: "税种",width: 100},
            {field: "GWEF006", title: "币种",width: 100},
            {field: "GWEF007", title: "汇率",width: 100,edit:'text'},
            {field: "GWEF008", title: "产品编号",width: 150},
            {field: "GWAML003", title: "品名",width: 200},
            {field: "GWAML004", title: "规格",width: 100},
            {field: "GWEF009", title: "数量",width: 100,edit:'text'},
            {field: "GWEF010", title: "原币单价",width: 100,edit:'text'},
            {field: "GWEF011", title: "原币含税金额",width: 100,edit:'text'},
            {field: "GWEF012", title: "原币税额",width: 100,edit:'text'},
            {field: "GWEF013", title: "原币不含税金额",width: 100,edit:'text'},
            {field: "GWEF014", title: "本币单价",width: 100,edit:'text'},
            {field: "GWEF015", title: "含税金额",width: 100,edit:'text'},
            {field: "GWEF016", title: "税额",width: 100,edit:'text'},
            {field: "GWEF017", title: "不含税金额",width: 100,edit:'text'},
            {field: "GWEFACTI", title: "有效否",width: 100,filterDatas: app.datas_('sys_y_n')},
            {field: "GWEA006", hide: true}, // 税率
            {field: "GWEF019", hide: true}, // 申请单号项次
            {field: "GWEF101", hide: true}, // 出货单项次
            {field: "GWEF002", hide: true}, // 客户编号
            {field: "MAX_NUM", hide: true},
        ]],
        callObj,
        listData = null,
        pageVue,
        table, gwei007EditTable,layOpenIndex
    ;

    var Gwei007Edit = app.Module.extend({
            init: function () {
                self = this;
                self._super({
                    _tag: 'gwei007_edit',
                    _loadTplsFull: [
                        {
                            dom: 'gwei007_edit_add', tpl: 'gwei007_edit_add'
                        },
                        {
                            dom: 'common_open_window', tpl: 'common/_open_window'
                        }
                    ]
                }, win);
            },
            initTable: function () {
                layui.use(['table'], function () {
                    table = layui.table;
                    gwei007EditTable = table.render({
                        elem: app.getByid(doc, 'gwei007_edit_table'),
                        id: 'gwei007_edit_table',
                        height:'240',
                        cols: cols,
                        data: listData,
                        totalRow: true
                    });

                });
                table.on('edit(gwei007_edit_table)', function(obj){
                    var oldValue = $(this).prev().text();

                    self.numFormatBeforeCalulate(obj.data);

                    if(obj.field === 'GWEF009') {
                        self.onGwef009Change(obj,oldValue);
                    }else {
                        var checkResult = self.checkMoney(obj,oldValue);
                        if(!checkResult) return;
                        switch (obj.field) {
                            case 'GWEF007': // 汇率
                                self.onGwef007Change(obj);
                                break;
                            case 'GWEF010': // 原币单价
                                self.onGwef010Change(obj);
                                break;
                            case 'GWEF011': // 原币含税金额
                                self.onGwef011Change(obj);
                                break;
                            case 'GWEF012': // 原币税额
                                self.onGwef012Change(obj);
                                break;
                            case 'GWEF014': // 本币单价
                                self.onGwef014Change(obj);
                                break;
                            case 'GWEF015': // 本币含税金额
                                self.onGwef015Change(obj);
                                break;
                            case 'GWEF016': // 本币税额
                                self.onGwef016Change(obj);
                                break;
                        }
                    }
                    self.numFormatAfterCalulate(obj.data);
                    obj.updateOfEdit({
                        GWEF007:obj.data.GWEF007,
                        GWEF009:obj.data.GWEF009,
                        GWEF010:obj.data.GWEF010,
                        GWEF011:obj.data.GWEF011,
                        GWEF012:obj.data.GWEF012,
                        GWEF013:obj.data.GWEF013,
                        GWEF014:obj.data.GWEF014,
                        GWEF015:obj.data.GWEF015,
                        GWEF016:obj.data.GWEF016,
                        GWEF017:obj.data.GWEF017
                    });

                    self.calTotal(gwei007EditTable.getDatas());

                });
            },

            numFormatUtil: function(num ,digit) {
                return math.div(Math.round(math.mul(num,digit)) ,digit);
            },

            numFormatBeforeCalulate: function(data){
                data.GWEF009 = parseInt(data.GWEF009);
                data.GWEF007 = parseFloat(data.GWEF007);
                data.GWEF010 = parseFloat(data.GWEF010);
                data.GWEF011 = parseFloat(data.GWEF011);
                data.GWEF012 = parseFloat(data.GWEF012);
                data.GWEF013 = parseFloat(data.GWEF013);
                data.GWEF014 = parseFloat(data.GWEF014);
                data.GWEF015 = parseFloat(data.GWEF015);
                data.GWEF016 = parseFloat(data.GWEF016);
                data.GWEF017 = parseFloat(data.GWEF017);
            },

            numFormatAfterCalulate: function(data){
                var rate = vueData.digit.rate;
                var price = vueData.digit.price;
                var amount = vueData.digit.amount;
                data.GWEF007 = self.numFormatUtil(data.GWEF007,rate);
                data.GWEF010 = self.numFormatUtil(data.GWEF010,price);
                data.GWEF011 = self.numFormatUtil(data.GWEF011,amount);
                data.GWEF012 = self.numFormatUtil(data.GWEF012,amount);
                data.GWEF013 = self.numFormatUtil(data.GWEF013,amount);
                data.GWEF014 = self.numFormatUtil(data.GWEF014,price);
                data.GWEF015 = self.numFormatUtil(data.GWEF015,amount);
                data.GWEF016 = self.numFormatUtil(data.GWEF016,amount);
                data.GWEF017 = self.numFormatUtil(data.GWEF017,amount);
            },

            calTotal:function(data) {
            var _total = {
                rows: data.length,
                num: 0,
                original_taxSum: 0,
                original_tax:0,
                original_sum:0,
                taxSum: 0,
                tax:0,
                sum:0
            };
            data.forEach(function (v) {
                _total.num = math.add(_total.num,v.GWEF009);
                _total.original_taxSum = math.add(_total.original_taxSum,v.GWEF011);
                _total.original_tax = math.add(_total.original_tax,v.GWEF012);
                _total.original_sum = math.add(_total.original_sum,v.GWEF013);
                _total.taxSum = math.add(_total.taxSum,v.GWEF015);
                _total.tax = math.add(_total.tax,v.GWEF016);
                _total.sum = math.add(_total.sum,v.GWEF017);
            })
            app.extendUpLow({
                target: vueData.total,
                res:_total,
                reset: true
            })
        },

            checkMoney: function(obj,oldValue) {
                var flag = true;
                var re = /^[0-9]+.?[0-9]*$/;

                var field = obj.field;
                var title='';
                var _cols = cols[0];
                for(var i=0;i<_cols.length;i++) {
                    if(_cols[i].field === field) {
                        title = _cols[i].title;
                        break;
                    }
                }

                if((!re.test(obj.value)) || parseFloat(obj.value) <= 0 ){
                    obj[field] = oldValue;

                    obj.updateOfEdit({
                        [field]: obj[field]
                    });
                    app.showWarning(title + "应为数字类型！");
                    flag = false;
                    return flag;
                }
                obj[field] = obj.value;

                return flag;
            },


            onGwef007Change:function(obj) { // 汇率
                var data = obj.data;
                var GWEF007 = data.GWEF007;
                var GWEF010 = data.GWEF010;
                var GWEF009 = data.GWEF009;
                var GWEA006 = math.div(data.GWEA006,100);

                data.GWEF014 = math.div(GWEF010, GWEF007);  // 本币单价
                data.GWEF015 =  math.mul((math.div(GWEF010,GWEF007)), GWEF009) ; // 本币含税金额
                data.GWEF016 = math.mul(math.mul(( math.div(GWEF010, GWEF007) ) , GWEF009) , GWEA006); // 本币税额
                data.GWEF017 = math.mul(math.mul(( math.div(GWEF010, GWEF007) ) , GWEF009) , (1-GWEA006));  // 本币税后金额
            },

            onGwef009Change:function(obj,oldValue) {
                var data = obj.data;

                var re = /^[0-9]*$/; //判断是否正整数
                if((!re.test(obj.value)) || parseFloat(obj.value) <= 0 ){
                    data.GWEF009 = oldValue;
                    obj.updateOfEdit({
                        GWEF009: oldValue
                    });

                    app.showWarning("数量为应为正整数！");
                    return ;
                } else {
                    var gwef009_sum = parseFloat(obj.data.MAX_NUM); // 出货数量（可开票数量）
                    var gwef009 = parseFloat(obj.value);
                    if(gwef009 > gwef009_sum) {
                        data.GWEF009 = oldValue;
                        obj.updateOfEdit({
                            GWEF009: oldValue
                        });
                        app.showWarning("本次开票数量不能大于可开票数量！(" + gwef009_sum + ")");
                    }
                }

                var GWEF009 = data.GWEF009;
                var GWEF010 = data.GWEF010;
                var GWEF014 = data.GWEF014;
                var GWEA006 = math.div(data.GWEA006,100);
                data.GWEF011 = math.mul(GWEF010 , GWEF009);
                data.GWEF012 = math.mul(math.mul(GWEF010 , GWEF009 ), GWEA006);
                data.GWEF013 = math.mul(math.mul(GWEF010 , GWEF009 ), (1-GWEA006));
                data.GWEF015 = math.mul(GWEF014 , GWEF009);
                data.GWEF016 = math.mul(math.mul(GWEF014 , GWEF009 ), GWEA006);
                data.GWEF017 = math.mul(math.mul(GWEF014 , GWEF009 ), GWEA006);
            },

            onGwef010Change:function(obj) {
                var data = obj.data;
                var GWEF010 = data.GWEF010;
                var GWEF009 = data.GWEF009;
                var GWEF007 = data.GWEF007;
                var GWEA006 = math.div(data.GWEA006,100);
                data.GWEF011 = math.mul(GWEF009 , GWEF010); //原币含税金额
                data.GWEF012 = math.mul(math.mul(GWEF009 , GWEF010 ) , GWEA006); // 原币税额
                data.GWEF013 = math.mul(math.mul(GWEF009 , GWEF010 ), (1 - GWEA006)); // 原币税后金额
                data.GWEF014 = math.div(GWEF010 , GWEF007); // 本币单价
                data.GWEF015 = math.mul(math.div(GWEF010 , GWEF007 ) , GWEF009);// 本币含税金额
                data.GWEF016 = math.mul(math.mul(math.div(GWEF010 , GWEF007 ) , GWEF009 ), GWEA006);// 本币税额
                data.GWEF017 = math.mul(math.mul(math.div(GWEF010 , GWEF007 ) , GWEF009 ), (1 - GWEA006));// 本币税后金额
            },

            onGwef011Change:function(obj) { // 含税金额
                var data = obj.data;
                var GWEF011 = data.GWEF011;
                data.GWEF012 = (GWEF011 * data["GWEA006"]);  // 原币税额
                data.GWEF013 = (GWEF011 * (1 - data["GWEA006"] / 100));  // 原币不含税金额
            },

            onGwef012Change:function(obj) { // 原币税额
                var data = obj.data;
                var GWEF011 = data.GWEF011;
                var GWEF012 = data.GWEF012;
                data.GWEF013 = math.sub(GWEF011, GWEF012);
            },

            onGwef014Change:function(obj) { //税额
                var data = obj.data;
                var GWEF014 = data.GWEF014;
                var GWEF009 = data.GWEF009;
                var GWEA006 = math.div(data.GWEA006,100);
                data.GWEF015 = math.mul(GWEF014 , GWEF009);
                data.GWEF016 = math.mul(math.mul(GWEF014 , GWEF009) , GWEA006);
                data.GWEF017 = math.mul(math.mul(GWEF014 , GWEF009) , (1-GWEA006));
            },

            onGwef015Change:function(obj) { //本币含税金额
                var data = obj.data;
                var GWEF015 = data.GWEF015;
                var GWEA006 = math.div(data.GWEA006,100);
                data.GWEF016 = math.mul(GWEF015 , GWEA006);
                data.GWEF017 = math.mul(GWEF015 , math.sub(1,GWEA006));
            },

            onGwef016Change:function(obj) { //本币含税金额
                var data = obj.data;
                var GWEF016 = data.GWEF016;
                data.GWEF017 = math.sub(data["GWEF015"] , GWEF016);
            },

            tableReload: function (listData) {
                self._reloadTable({id: 'gwei007_edit_table', data: listData});
            },

            addData: function (listData) {
                app.ajax({
                    xurl: 'crm/gwei007/addData',
                    xdata: listData,
                    loading: true,
                    toJsonStr: true,
                    okmsg: '发票信息增加成功',
                    cb: function (result) {
                        if (result.ok) {
                            app.pageModule('gwei007').reloadTableCurr();
                            self._closeTpl();
                        }
                    }
                });
            },

            editData: function (listData) {
                app.ajax({
                    xurl: 'crm/gwei007/editData',
                    xdata: listData,
                    loading: false,
                    toJsonStr: true,
                    okmsg: '发票信息修改成功',
                    cb: function (result) {
                        if (result.ok) {
                            app.pageModule('gwei007').reloadTableCurr();
                            self._closeTpl();
                        }
                    }
                });
            },

            doOpenGwakPge: function() {
                self._openTplFull({
                    tag: 'common_open_window',
                    tagData: {
                        config: {
                            method:'cq_gwak001_1',
                            columnList: [
                                {label:'客户编号',prop:'GWAK001', width: 150},
                                {label:'客户简称',prop:'GWAKL003', width: 150},
                                {label:'客户全称',prop:'GWAKL004', width: 150}
                            ],
                        },
                        cb: function (data) {
                            vueData.form.GWEF002 = data.GWAK001;
                            vueData.form.GWEF002_NAME = data.GWAKL004;
                        }
                    },
                    index: 1,
                    openOpts: {
                        title: '选择客户',
                        area: ['600px', '465px']
                    }
                });
            },

            getDigit:function() {
                app.ajax({
                    xurl: 'admin/getDigit',
                    async: true,
                    cb: function (result) {
                        if(result.ok) {
                            var data = result.data.data;
                            var _digit = {
                                rate: Math.pow(10,data.rate),
                                price: Math.pow(10,data.price),
                                amount: Math.pow(10,data.amount),

                            }
                            app.extendUpLow({
                                target: vueData.digit,
                                res: _digit,
                                reset: true
                            })
                        }
                    }
                });
            },

            _call: function (tagData) {
                pageVue.$refs.form.resetFields();
                layOpenIndex = tagData.layOpenIndex;
                if (tagData.is_add) {
                    vueData.isAdd = true;
                    app.ajax({
                        xurl: 'crm/gwei007/getAddData',
                        cb: function (result) {
                            if (result.ok) {
                                var resData = result.data.data;
                                app.extendUpLow({
                                    target: vueData.form,
                                    res: {
                                        GWEFDOCNO: resData.GWEFDOCNO,
                                        GWEF020:resData.GWEF020,
                                        GWEF020_NAME:resData.GWEF020_NAME,
                                        GWEF021:resData.GWEF021,
                                        GWEF021_NAME : resData.GWEF021_NAME,
                                        GWEFDOCDATE: new Date().Format("yyyy-MM-dd")
                                    },
                                    reset: true
                                });

                                listData = [];
                                self.tableReload(listData);
                                self.calTotal(listData);
                            }
                        }
                    });
                } else {
                    vueData.isAdd = false;
                    callObj = tagData.obj;
                    app.ajax({
                        xurl: 'crm/gwei007/getDetailList',
                        xdata: {GWEFDOCNO: callObj.data.GWEFDOCNO},
                        loading: false,
                        cb: function (result) {
                            if(result.ok) {
                                app.extendUpLow({
                                    target: vueData.form,
                                    res: callObj.data,
                                    reset: true
                                });

                                listData = result.data.data;
                                vueData.form.GWEF107 = listData[0].GWEF107;
                                vueData.form.GWEF020 = listData[0].GWEF020;
                                vueData.form.GWEF020_NAME = listData[0].GWEF020_NAME;
                                vueData.form.GWEF021 = listData[0].GWEF021;
                                vueData.form.GWEF021_NAME = listData[0].GWEF021_NAME;
                                vueData.form.GWEFMLEGAL = listData[0].GWEFMLEGAL;
                                vueData.form.GWEFMLEGAL_NAME = listData[0].GWEFMLEGAL_NAME;
                                vueData.form.GWEFPLANT = listData[0].GWEFPLANT;
                                vueData.form.GWEFPLANT_NAME = listData[0].GWEFPLANT_NAME;

                            }else {
                                listData = [];
                            }
                            self.tableReload(listData);
                            self.calTotal(listData);
                        }
                    });
                }
            },

            _ready: function () {
                table = layui.table;
                vueData.form = app.fields_(['GWEF_T'],vueData.form);
                pageVue = new Vue({
                    el: '#gwei007_edit',
                    data: vueData,
                    watch: {
                        'form.GWEF020': function () { // 人员变动
                            app.ajax({
                                xurl: 'crm/gwei006/getGwed101',
                                xdata: {GWED001: vueData.form.GWEF020},
                                loading: false,
                                cb: function (result) {
                                    if (result.ok) {
                                        vueData.form.GWEF021= result.data.data.GWED101;
                                        vueData.form.GWEF021_NAME = result.data.data.GWED101_NAME;
                                    }
                                }
                            });
                        }
                    },
                    methods: {
                        cancle: function () {
                            self._closeTpl();
                        },
                        saveData: function () {
                            this.$refs['form'].validate(function (valid) {
                                if (valid) {
                                    var listData = gwei007EditTable.getDatas();
                                    if(listData.length == 0){
                                        app.showWarning('表格不能为空!');
                                        return;
                                    }
                                    for (var i = 0; i < listData.length; i++) {
                                        var v = listData[i];
                                        if (v.GWEF009 <= 0) {
                                            app.showWarning('存在产品数量不大于0的数据，请修改!');
                                            return;
                                        }
                                    }
                                    listData.addMap({
                                        GWEFDOCDATE: vueData.form.GWEFDOCDATE, // 开票日期
                                        GWEF002: vueData.form.GWEF002,  // 客户
                                        GWEFDOCNO: vueData.form.GWEFDOCNO,  // 开票单号
                                        GWEF021: vueData.form.GWEF021,  // 归属组织
                                        GWEF020: vueData.form.GWEF020,  // 申请人员
                                        GWEFMLEGAL: vueData.form.GWEFMLEGAL,  // 法人
                                        GWEFPLANT: vueData.form.GWEFPLANT,  // 营运中心
                                        GWEF107: vueData.form.GWEF107,  // 发票号码
                                        GWEF018: vueData.form.GWEF018,  // 备注
                                        GWEFCONF: vueData.form.GWEFCONF,
                                        GWEFACTI: 'Y'
                                    },true);
                                    if (vueData.isAdd) {
                                        self.addData(listData);
                                    } else {
                                        self.editData(listData);
                                    }
                                }
                            });
                        },

                        addData: function () {
                            var formData = vueData.form;
                            var listData = gwei007EditTable.getDatas();
                            if (formData.GWEF002_NAME == null) {
                                app.showWarning('请先选择客户');
                                return;
                            }
                            if (vueData.form.GWEFMLEGAL_NAME == null) {
                                app.showWarning('请先选择归属法人');
                                return;
                            }
                            var gwedlist = [];
                            listData.forEach(function (v) {
                                gwedlist.push(v.GWEF001 + v.GWED102);
                            });
                            formData.gwedlist = gwedlist.join(",");

                            self._openTplFull({
                                tag: 'gwei007_edit_add',
                                tagData: {
                                    obj: formData,
                                    cb : function (data) {
                                        var GWEF019 = '';
                                        var GWEF005 = '';
                                        var GWEF006 = '';
                                        var GWEF007 = 1;
                                        var GWEA006 = 0;

                                        var tableData = gwei007EditTable.getDatas();
                                        var length = tableData.length;
                                        var num = 0;
                                        if (length !== 0) {
                                            num = parseInt(tableData[length - 1].GWEFSEQ);
                                        }


                                        for (let i = 0; i < data.length; i++) {
                                            if (data[i]["GWEA006"] != null && data[i]["GWEA006"] != '' && data[i]["GWEA006"] != undefined) {
                                                GWEA006 = data[i]["GWEA006"];
                                            }
                                            if (data[i]["GWAP014"] != null && data[i]["GWAP014"] != '' && data[i]["GWAP014"] != undefined) {
                                                GWEF005 = data[i]["GWAP014"];
                                            }
                                            if (data[i]["GWAP005"] != null && data[i]["GWAP005"] != '' && data[i]["GWAP005"] != undefined) {
                                                GWEF006 = data[i]["GWAP005"];
                                            }
                                            if (data[i]["GWEF007"] != null && data[i]["GWEF007"] != '' && data[i]["GWEF007"] != undefined) {
                                                GWEF007 = data[i]["GWEF007"];
                                            }
                                            var GWEF009 = data[i]["GWED009"] - data[i]["GWEF009_SUM"];
                                            var GWED010 = data[i].GWED010;
                                            var taxRate = math.div(GWEA006,100);
                                            var ex_taxRate = math.sub(1,taxRate);
                                            let temp = {
                                                GWEFSEQ : num + (i + 1) ,
                                                GWEF001 : data[i]["GWEDDOCNO"],
                                                GWEF002 : data[i]["GWED004"],
                                                GWEF003 : data[i]["GWED003"],
                                                GWED102 : data[i]["GWED102"],
                                                GWEF004 : data[i]["GWEC003"],
                                                GWEC101 : data[i]["GWEC101"],
                                                GWEF005 : GWEF005,
                                                GWEF006 : GWEF006,
                                                GWEF007 : GWEF007,
                                                GWEF008 : data[i]["GWED008"],
                                                GWAML003 : data[i]["GWAML003"],
                                                GWAML004 : data[i]["GWAML004"],
                                                GWEF009 : GWEF009,
                                                GWEF010 : GWED010,
                                                GWEF011 : math.mul(GWEF009 , GWED010),
                                                GWEF012 : math.mul(math.mul(GWEF009 , GWED010)  , taxRate),
                                                GWEF013 : math.mul(math.mul(GWEF009 , GWED010), ex_taxRate),
                                                GWEF014 : math.div(GWED010 , GWEF007),
                                                GWEF015 : math.div(math.mul(GWEF009 , GWED010 ), GWEF007),
                                                GWEF016 : math.mul(math.div(math.mul(GWEF009 , GWED010 ), GWEF007) , taxRate),
                                                GWEF017 : math.mul(math.div(math.mul(GWEF009 , GWED010 ), GWEF007) , ex_taxRate),
                                                GWEFACTI : 'Y',
                                                GWEA006 : GWEA006,
                                                GWEF019 : GWEF019,
                                                GWEF101 : data[i]["GWEDSEQ"],
                                                GWAKL003 : data[i]["GWAKL003"],
                                                MAX_NUM : GWEF009
                                            };
                                            self.numFormatAfterCalulate(temp);
                                            listData.push(temp);
                                        }
                                        listData.addMap({
                                            GWEFDOCNO: vueData.form.GWEFDOCNO,  // 开票单号
                                            GWEFDOCDATE: vueData.form.GWEFDOCDATE, // 开票日期
                                            GWEF001: vueData.form.GWEF001,  // 申请单号
                                            GWEF002: vueData.form.GWEF002,  // 客户
                                            GWEF002_NAME: vueData.form.GWEF002_NAME,
                                            GWEFACTI: 'Y'
                                        });
                                        self.tableReload(listData);
                                        self.calTotal(listData);
                                    }
                                },
                                index: 0,
                                openOpts: {
                                    title: '选择开票申请',
                                    area: ['1000px', '500px']
                                }
                            });
                        },

                        del: function () {
                            var list = gwei007EditTable.getDatas();
                            var checkStatus = table.checkStatus('gwei007_edit_table');
                            if (checkStatus.data.length > 0) {
                                checkStatus.data.forEach(function (v) {
                                    list.removeByMap({
                                        GWEFSEQ: v.GWEFSEQ
                                    });
                                });
                                if (list.length != 0) {
                                    var i = 1;
                                    list.forEach(function (v) {
                                        v.GWEFSEQ = i;
                                        i++;
                                    });
                                }
                                self.tableReload(list);
                                self.calTotal(list);
                            } else {
                                app.showWarning("至少选择一笔数据进行操作")
                            }
                        },

                        // 客户开窗
                        openGwakPage:function () {
                            var listData = gwei007EditTable.getDatas();
                            // 客户不为空
                            if (vueData.form.GWEF004 != '' && vueData.form.GWEF004 != null) {
                                if(listData.length > 0){
                                    app.confirm({
                                        msg: '修改客户将清空表格信息，是否确认修改？',
                                        ok: function () {
                                            listData = [];
                                            self.tableReload(listData);
                                            self.calTotal(listData);
                                            self.doOpenGwakPge();
                                        }
                                    });
                                }else {
                                    self.doOpenGwakPge();
                                }
                            }else {
                                self.doOpenGwakPge();
                            }

                        },

                        // 组织开窗
                        openGwef021:function () {
                            self._openTplFull({
                                tag: 'common_open_window',
                                tagData: {
                                    config: {
                                        method:'q_sysorg_id',
                                        columnList: [
                                            {label: '组织编号', prop: 'ID', width: '150'},
                                            {label: '组织名称', prop: 'NAME', width: '150'}
                                        ],
                                    },
                                    cb: function (data) {
                                        vueData.form.GWEF021 = data.ID;
                                        vueData.form.GWEF021_NAME = data.NAME;
                                    }
                                },
                                index: 1,
                                openOpts: {
                                    title: '选择归属组织信息',
                                    area: ['600px', '465px']
                                }
                            });
                        },

                        // 归属法人以及营运中心开窗
                        openGwefmlegal:function () {
                            self._openTplFull({
                                tag: 'common_open_window',
                                tagData: {
                                    config: {
                                        method: 'cq_sysorg_biz_1',
                                        columnList: [
                                            {label: 'ID', prop: 'ID', width: '150'},
                                            {label: '归属法人', prop: 'NAME', width: '150'},
                                            {label: '营运中心编号', prop: 'AZP01', width: '150',sortable:false,unshow:true},
                                            // {label: '营运中心名称', prop: 'AZP02', width: '150',sortable:false,unshow:true}
                                        ],
                                    },
                                    cb: function (data) {
                                        vueData.form.GWEFMLEGAL = data.ID;
                                        vueData.form.GWEFMLEGAL_NAME = data.NAME;
                                        vueData.form.GWEFPLANT = data.AZP01;
                                        vueData.form.GWEFPLANT_NAME = data.AZP02;
                                    }
                                },
                                index: 1,
                                openOpts: {
                                    title: '选择归属法人',
                                    area: ['700px', '465px']
                                }
                            });
                        },

                        // 申请人员开窗 （引用销售人员开窗）
                        openGwef020: function () {
                            self._openTplFull({
                                tag: 'common_open_window',
                                tagData: {
                                    config: {
                                        method:'q_sysuser_id',
                                        columnList: [
                                            {label: '申请人员编号', prop: 'ID', width: '150'},
                                            {label: '申请人员名称', prop: 'NAME', width: '150'}
                                        ],
                                    },
                                    cb: function (data) {
                                        vueData.form.GWEF020 = data.ID;
                                        vueData.form.GWEF020_NAME = data.NAME;
                                    }
                                },
                                index: 1,
                                openOpts: {
                                    title: '选择申请人员',
                                    area: ['600px', '465px']
                                }
                            });
                        },
                        clearMlegal:function () {
                            if(vueData.form.GWEFMLEGAL_NAME == '' || vueData.form.GWEFMLEGAL_NAME == null){
                                vueData.form.GWEFPLANT = '';
                                vueData.form.GWEFPLANT_NAME = '';
                            }
                        },
                        clearGwef002:function() {
                            vueData.form.GWEF002 = "";
                            vueData.form.GWEF002_NAME = "";
                        },
                        clearGwef020:function() {
                            vueData.form.GWEF020 = "";
                            vueData.form.GWEF020_NAME = "";
                        },
                        clearGwef021:function() {
                            vueData.form.GWEF021 = "";
                            vueData.form.GWEF021_NAME = "";
                        }

                    },
                    created: function () {
                        self._setEleIsReady('gwei007_edit');
                    }
                });
                self.initTable();
            },
            _lazy: function () {
                this._super();
                this.getDigit();
            }
        })
    ;

    return new Gwei007Edit();

})
;